package cu.ds.logicalsync.fytasrealm.model;

import java.util.Random;

public class Battle {

	private Warrior warriorOwner;
	private Warrior warriorPair;
	private String worldName;
	
	public Battle(Warrior w1,Warrior w2) {
		this.warriorOwner = w1;
		this.warriorPair = w2;
		this.worldName = this.warriorOwner.getMyWorld().getWorldName();
		this.warriorOwner.setWarriorState(true);
		this.warriorPair.setWarriorState(true);
	}
	
	public Warrior getWarriorOwner() {
		return warriorOwner;
	}

	public void setWarriorOwner(Warrior warriorOwner) {
		this.warriorOwner = warriorOwner;
	}

	public Warrior getWarriorPair(Warrior w) {
		if (this.warriorOwner == w) {
			return this.warriorPair;
		}
		else {
			return this.warriorOwner;
		}
	}

	public void setWarriorPair(Warrior warriorPair) {
		this.warriorPair = warriorPair;
	}

	public String getWorldName() {
		return worldName;
	}

	public void setWorldName(String worldName) {
		this.worldName = worldName;
	}
	
	public void sendAttack(Warrior sender, Warrior receiver) {
		boolean randResult = randomAttackResult();
		if (randResult) {
			//sender is win
			sender.setLost(false);
			//receiver is lost
			receiver.setLost(true);
		}
		else {
			//sender is lost
			sender.setLost(true);
			//receiver is win
			receiver.setLost(false);
		}
	}
	
	public boolean randomAttackResult() {
		Random generator = new Random();
		boolean randomResult = generator.nextBoolean();
		return randomResult;
	}
	
}
